package com.tarena.luban.sentinel.study.demo01.service.impl;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tarena.luban.sentinel.study.demo01.repository.HelloRepository;
import com.tarena.luban.sentinel.study.demo01.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class HelloServiceImpl implements HelloService {
    @Autowired
    private HelloRepository helloRepository;
    @Override
    public String sayHello(String name) {
        //资源入口
        Entry entry=null;
        try{
            entry= SphU.entry("serviceSayHello");
            String result=helloRepository.sayHello(name);
            return result;
        }catch (BlockException e){
            log.info("业务层资源serviceSayHello受到限制",e);
        }finally {
            if (entry!=null){
                entry.exit();
            }
        }
        return "service error";

    }
}
